package com.livi.tools.cas_general_backend.exception;

import com.livi.tools.cas_general_backend.entity.response.Res;
import com.livi.tools.cas_general_backend.entity.response.ResStatusEnum;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author Livi Luo
 */
@ControllerAdvice
@RestControllerAdvice
public class UnifiedExceptionHandle {

    private static final Logger logger = LogManager.getLogger("err");

    /**
     * description: errorHandler 全局异常<br>
     */
    @ResponseBody
    @ExceptionHandler({Exception.class})
    public Res errorHandler(Exception e) {
        logger.error("unknown exception：" + e);
        return Res.fail(ResStatusEnum.error, "unknown exception：" + e.getMessage());
    }

}
